package com.bookmarket.controller;

import com.bookmarket.entity.Book;
import com.bookmarket.entity.Custom;
import com.bookmarket.entity.Mess;
import com.bookmarket.service.LLOrderService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * OrderController
 *
 * @author 李亮
 * @date 2018/1/3
 */
@RestController
@RequestMapping("/order")
public class LLOrderController {
    @Resource
    LLOrderService orderService;


    @RequestMapping("/queren")
    public ModelAndView queren(int id) {
        orderService.update(id,2);
        ModelAndView mv = new ModelAndView();
        mv.setView(new MappingJackson2JsonView());
        return mv;
    }
    @RequestMapping("/tuihuo")
    public ModelAndView tuihuo(int id) {
        orderService.update(id,3);
        ModelAndView mv = new ModelAndView();
        mv.setView(new MappingJackson2JsonView());
        return mv;
    }

    @RequestMapping("/getorder")
    public Map queryUsersByPage(int pageNum, int pageSize,HttpSession session) {
        Custom custom=(Custom) session.getAttribute("NowCustom");
        Map map = new HashMap();
        ModelAndView mv = new ModelAndView();
        map.put("pageSize", pageSize);
        map.put("pageNum", pageNum);
        map.put("row", (pageNum - 1) * pageSize);
        map.put("id",custom.getId());
        Map map1 = orderService.getlist(map);
        return map1;
    }
    @RequestMapping("/getmess")
    public Map getMess1(int pageNum, int pageSize,HttpSession session) {
        Custom custom=(Custom) session.getAttribute("NowCustom");
        Map map = new HashMap();
        ModelAndView mv = new ModelAndView();
        map.put("pageSize", pageSize);
        map.put("pageNum", pageNum);
        map.put("row", (pageNum - 1) * pageSize);
        map.put("id",custom.getId());
        Map map1 = orderService.getmess(map);
        return map1;

    }

    @RequestMapping("/dell")
    public ModelAndView dell(int id) {
        orderService.dell(id);
        ModelAndView mv = new ModelAndView();
        mv.setView(new MappingJackson2JsonView());
        return mv;
    }
    @RequestMapping("/dellmess")
    public ModelAndView dellMess(int id) {
        orderService.dellmess(id);
        ModelAndView mv = new ModelAndView();
        mv.setView(new MappingJackson2JsonView());
        return mv;
    }
    @RequestMapping("/pinlun")
    public ModelAndView addpinlun(int id,float pinfen,String miaoshu ,HttpSession session){

        Custom custom=(Custom) session.getAttribute("NowCustom");
        Book  book=new Book(orderService.sel(id));
        Mess mess=new Mess(pinfen,miaoshu,custom,book);
        orderService.addmess(mess);
        ModelAndView mv = new ModelAndView();
        return mv;
    }
    @RequestMapping("/updatexinxi")
    public ModelAndView updatexinxi(String realName, String phone, String email, HttpSession session){
        Custom custom=(Custom) session.getAttribute("NowCustom");
        custom.setRealName(realName);
        custom.setPhone(phone);
        custom.setEmail(email);
       orderService.updatecus(custom);
        ModelAndView mv = new ModelAndView();
        session.setAttribute("NowCustom",custom);
        mv.setViewName("stage/LLgerenziliao");
        return mv;
    }



    public LLOrderService getOrderService() {
        return orderService;
    }

    public void setOrderService(LLOrderService orderService) {
        this.orderService = orderService;
    }
}